package diamondRingServlet;

import diamondRingService.impl.AdminServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/BackAddGoodsInfoServlet")
public class BackAddGoodsInfoServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        response.setCharacterEncoding("utf-8");
        PrintWriter out = response.getWriter();
        AdminServiceImpl adminService=new AdminServiceImpl();

        int count = 0;
        int ID = Integer.parseInt(request.getParameter("ID"));
        if (adminService.AddGoods(ID)>0){
            out.print("<script>\n" +
                    "    location.href=\"http://localhost:8080/DiamondRing/back-stage-Management/providerList.html\"\n" +
                    "    alert(\"上架成功!\");\n" +
                    "</script>");
        }else{
            out.print("<script>\n" +
                    "    location.href=\"http://localhost:8080/DiamondRing/back-stage-Management/providerList.html\"\n" +
                    "    alert(\"上架失败!\");\n" +
                    "</script>");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}